// cd /projects/data_commons/cw_code/
// qstata cw_ind_2_sic_imp.do &

global dir_proj = "/projects/data_commons/"
global dir_cw = "${dir_proj}/cw/"
global dir_lbd = "${dir_proj}/lbd/"

di "Started at $S_DATE $S_TIME"

cd ${dir_cw}/

//==============================================================================

import delimited "cw_ind_fk_raw_man.csv", clear varn(1)

do /projects/data_commons/cw_code/cw_ind_1_jsung_fix.do
f_jsung_naics_fix "fk_naics"

recast double ch_ind
replace ch_ind = round(ch_ind, 0.1)

keep ch_ind ch_ind_new
list if ch_ind == .
drop if ch_ind == .

keep if ch_ind_new != .
bysort ch_ind ch_ind_new: gen i_ind = 1 if _n == 1
by ch_ind: egen n_ind = total(i_ind)

keep if n_ind == 1
keep ch_ind ch_ind_new
duplicates drop
drop if ch_ind == .
di _N

merge 1:m ch_ind using "cw_ind_sic"
drop if sic == .

replace ch_ind = ch_ind_new if ch_ind_new != .
keep ch_ind sic
sort sic

save "cw_ind_sic_imp", replace
saveold "cw_ind_sic_imp_v12", replace v(12)
export delimited "cw_ind_sic_imp.csv", replace

di "Ended at $S_DATE $S_TIME"
// End of do file
